package com.happyghost.algorithm;

public class ReverseString {

    public static void reverseString(char[] s) {

        char temp;
        int i = 0;
        int j = s.length - 1;
        while(i <= j){
            temp = s[i];
            s[i] = s[j];
            s[j] = temp;
            i++;
            j--;
        }
    }

    public static void main(String[] args) {
        char[] chars = new char[]{'j','a','v','a','b'};
//        reverseString(chars);
        reverseString2(chars);
        System.out.println(chars);


    }


    public static void reverseString2(char[] s) {
        int n = s.length;
        for (int i = 0; i < n / 2; ++i) {
            int j = n - 1 - i;
            s[i] ^= s[j];
            s[j] ^= s[i];
            s[i] ^= s[j];
        }
    }

}
